package com.clstu.homeworks;

public class HomeWork06 {
    public static void main(String[] args) {
        Doctor doctor = new Doctor("jack", 20, "doctor", "man", 20000);
        Doctor doctor01=doctor;
        Doctor doctor02 = new Doctor("jack", 20, "doctor", "man", 20000);
        Doctor doctor03 = new Doctor("jack", 21, "doctor", "man", 20000);
        System.out.println(doctor.equals(doctor01));//true
        System.out.println(doctor.equals(doctor02));//true
        System.out.println(doctor.equals(doctor03));//false
        System.out.println(doctor01.equals(doctor03));//false


    }
}

class Doctor{
    private String name;
    private int age;
    private String job;
    private String gender;
    private double sal;

    public Doctor(String name, int age, String job, String gender, double sal) {
        this.name = name;
        this.age = age;
        this.job = job;
        this.gender = gender;
        this.sal = sal;
    }

    public boolean equals(Object obj){
        if(this==obj) return true;
        if(obj instanceof Doctor){//满足就 向下转型判断
//            if(((Doctor) obj).name.equals(this.name)&&((Doctor) obj).age==this.age&&
//                    ((Doctor) obj).job.equals(this.job)&&((Doctor) obj).gender.equals(this.gender)&&
//                    ((Doctor) obj).sal==this.sal)
//                return true;

            //写法2
            Doctor d=(Doctor) obj;//向下转型才可以调用特有方法和变量   (private 类型的变量也可以直接访问）
            System.out.println(d.name);//直接访问了转型后的对象的私有变量，只有在向下转型这样的特殊情况下才可以做到
            return d.name.equals(this.name)&&d.age==this.age&&d.job.equals(this.job)&&d.gender.equals(this.gender)&&
                    d.sal==this.sal;
        }
        return false;
    }
}